package ynu.lcy.elememicroserviceuserauthservice9091.entity;



import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;
import org.springframework.util.DigestUtils;
import ynu.lcy.elememicroservicecommon.entity.LogicEntity;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Inheritance;

@Setter
@Getter
@Entity
@Inheritance
@Where(clause = "is_deleted = 0")
@DiscriminatorColumn(name = "userRole")
public abstract class User extends LogicEntity {
    @Column(unique = true)
    protected String userPhone;
    @Column
    protected String userName;

    @Column
    protected String password;

    @Column
    protected String userAvatar;

    /**
     * 创建所有User时，密码经过md5加密
     * @param psd
     */
    public void setPassword(String psd){
        this.password = DigestUtils.md5DigestAsHex(psd.getBytes());
    }

    @Column(updatable = false, insertable = false)
    protected String userRole;

}
